#include "Projection_GPU.h"
#include "ApplyRigidTransform.h"


Projection_GPU::Projection_GPU(const int k, int width, int height){
	this->k = k;
	this->width = width;
	this->height = height;
	dim = new ApplyRigidTransform();
	initMemory();
	
}

Projection_GPU::~Projection_GPU(){
	cudaFree(temp);
	cudaFree(normal);
	delete dim;
	dim = 0;
}

void Projection_GPU::setIntrinsicInv(const cv::Mat& intrinsic_inv){
	for(int i=0; i<3; i++){
		for(int j=0; j<3; j++){
			Intrinsic_Inv[i*3+j] = (float)intrinsic_inv.at<double>(i, j);
			//std::cout << Intrinsic_Inv[i*3+j] << std::endl;
		}
	}
	
}
void Projection_GPU::initMemory(){
	Intrinsic_Inv = new float[9];
	output_CPU = new float3[width * height];
	cudaMalloc(&temp, width * height * sizeof(float3));
	cudaMalloc(&normal, k * sizeof(float4));
}

void Projection_GPU::setClusterNormals(float4* in){
	cudaMemcpy(normal, in, k * sizeof(float4), cudaMemcpyHostToDevice);
}

void Projection_GPU::setClusterMap(int* labels){
	this->labels = labels;
}
